package com.naiking.util
{
	import flash.geom.Point;

	public class NMath
	{
		/**获取随机整数*/
		public static function getRandomInteger(range:int):int
		{
			if(range>0)
				return Math.round(Math.random()*range);	
			return 0;
		}
		/**获取最大值 */		
		public static function getMaxiMum(array:Array):Number
		{
			array.sort(Array.NUMERIC);
			return array[array.length-1];
		}
		/**获取最小值 */		
		public static function getMimiMum(array:Array):Number
		{
			array.sort(Array.NUMERIC);
			return array[0];
		}
		/**
		 *精确到小数点后面几位 
		 * @param value 原始值
		 * @param accuracy保留几位小数
		 * 
		 */		
		public static function getAccuracyValue(value:Number,accuracy:int=2):Number
		{
			if(accuracy>10||accuracy<=0)
			{
				throw new Error("精确度应为（0 10]范围");
				return null;
			}
			var scaleParam:int=Math.pow(10,accuracy);
			return Math.round(value*scaleParam)/scaleParam;
		}
		/**数字变汉字*/
		public static function numToHanZi(num:int):String
		{
			var ary:Array=["零","一","二","三","四","五","六","七","八","九"];
			if(num>9||num<0)
				return "数字范围错误";
			return ary[num];
		}
		/**从2个数组中找到减少的元素索引*/
		public static function getRemovedItem(oldAry:Array,newAry:Array):Array
		{
			var ary:Array = [];
			for (var i:int=0; i<oldAry.length; i++)
			{
				
				if (newAry.indexOf(oldAry[i]) == -1)
				{
					ary.push(oldAry[i]);
				}
				
			}
			return ary;
		}
		/**
		 *从随机种子Point获取某范围内的随机点 
		 * @param seedPoint 种子坐标
		 * @param left
		 * @param right
		 * @param top
		 * @param bottom
		 * @return 
		 * 
		 */		
		public static function getRandomPoint(seedPoint:Point,left:int,right:int,top:int,bottom:int):Point
		{
			//左顶
			var ltP:Point=new Point(seedPoint.x-left,seedPoint.y-top);
			//右底
			var rbP:Point=new Point(seedPoint.x+right,seedPoint.y+bottom);
			var disW:int=rbP.x-ltP.x;
			var disH:int=rbP.y-ltP.y;
			var randomW:int=Math.random()*disW;
			var randomH:int=Math.random()*disH;
			var pt:Point=new Point((ltP.x+randomW),(ltP.y+randomH));
			return pt;
		}
		/**从2个数组中找到增加的元素索引*/
		public static function getAddItem(oldAry:Array,newAry:Array):Array
		{
			var ary:Array = [];
			for (var i:int=0; i<newAry.length; i++)
			{
				if (oldAry.indexOf(newAry[i]) == -1)
				{
					ary.push(newAry[i]);
				}
				
			}
			return ary;
		}
		public function NMath()
		{
		}
	}
}